//
//  GetPinYinInfo.m
//  ContactInfo
//
//  Created by  on 12-5-17.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "GetPinYinInfo.h"
#import "ChineseToPinyin.h"
#import "RegexKitLite.h"
@implementation GetPinYinInfo
+ (NSString *)getFullPinyinString:(NSString *)str {
    
    //    NSString *sTmp = @"";
    //modify by wqy 2012.8.21
    NSString *sTmp = nil;
    
    //NSLog(@"str===%@,--------%d",str,[str length]);
    
    NSString *textStr = nil ;
    
    for (int i = 0; i<[str length]; i++) {
        
        NSString *tempStr = [NSString stringWithFormat:@"%C",[str characterAtIndex:i]];
        
        if ([tempStr isMatchedByRegex:@"[\u4e00-\u9fa5]"])
        {
            sTmp = [ChineseToPinyin pinyinFromChiniseString:tempStr];
        }
        else
            sTmp = tempStr;
        
        
        if (textStr == nil) {
            textStr = sTmp;
        }
        else
            textStr = [textStr stringByAppendingString:sTmp];
        
    }
    //    sTmp = [ChineseToPinyin pinyinFromChiniseString:str];   modify by wqy 2012.8.21
    
    //NSLog(@"text---%@",textStr);
    return textStr;
}

+(NSString*)getFirsrPingyinString:(NSString *)str
{
    NSString *sTmp = @"";
    
    NSString *textStr = nil ;
    
    for (int i =0 ; i<[str length]; i++) {
        
        NSString *tempStr = [NSString stringWithFormat:@"%C",[str characterAtIndex:i]];
        
        if ([tempStr isMatchedByRegex:@"[\u4e00-\u9fa5]"])
        {
            sTmp = [NSString stringWithFormat:@"%c",pinyinFirstLetter([str characterAtIndex:i])];
        }
        else
        {
            sTmp = [NSString stringWithFormat:@"%c",[str characterAtIndex:i]];
        }
        if (textStr == nil) {
            textStr = sTmp;
        }
        else
            textStr = [textStr stringByAppendingString:sTmp];
        
    }
    
    NSLog(@"---%@",textStr);
    return textStr;
}
@end
